public with sharing class WeiboTestController {
    public string req{get;set;}
    public string msg{get;set;}
    public string json{get;set;}
    //----------- search_suggestions_users -----------
    public void doTest_search_suggestions_users(){
        try{
            WB_OpenApi.WB_search_suggestions_users_in wb_in = new WB_OpenApi.WB_search_suggestions_users_in(); 
            wb_in.q = 'keyword';
            req = wb_in.toRequestUrl();
            string jsonResult = WBUtil.sendRequest(req);
            if(jsonResult.indexOf('error',0) == -1){
                // get response content
                WB_OpenApi.WB_search_suggestions_users_out_array wb_out = new WB_OpenApi.WB_search_suggestions_users_out_array();
                WB_OpenApi.WB_search_suggestions_users_out_array arr = wb_out.parse(jsonResult); 
                msg ='';
                for(WB_OpenApi.WB_search_suggestions_users_out o :arr.lst_data){
                    msg += '' + o;
                }
                //msg = '' + outList;
            }
            else{
                msg = 'error';
            }
            json = jsonResult;
        }
        catch(Exception e){
             ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, e.getMessage()));
        }
    }
    //----------- WB_users_show -----------
    public void doTest_users_show(){
        try{
            WB_OpenApi.WB_users_show_in wb_in = new WB_OpenApi.WB_users_show_in(); 
            wb_in.uid ='1406592607';
            req = wb_in.toRequestUrl();
            string jsonResult = WBUtil.sendRequest(req,'GET');
            json = jsonResult;
            if(jsonResult.indexOf('error',0) == -1){
                // get response content
                WB_OpenApi.WB_users_show_out wb_out = new WB_OpenApi.WB_users_show_out();
                WB_OpenApi.WB_users_show_out o = wb_out.parse(jsonResult); 
                msg = '' + o;
            }
            else{
                msg = 'error';
            }
        }
        catch(Exception e){
             ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, e.getMessage()));
        }
    }
    //----------- WB statuses user timeline -----------
    public void doTest_statuses_user_timeline(){
        try{
            WB_OpenApi.WB_statuses_user_timeline_in wb_in = new WB_OpenApi.WB_statuses_user_timeline_in(); 
            wb_in.uid ='1406592607';
            req = wb_in.toRequestUrl();
            string jsonResult = WBUtil.sendRequest(req,'GET');
            json = jsonResult;
            if(jsonResult.indexOf('error',0) == -1){
                // get response content
                WB_OpenApi.WB_statuses_user_timeline_out_array wb_out = new WB_OpenApi.WB_statuses_user_timeline_out_array();
                WB_OpenApi.WB_statuses_user_timeline_out_array o = wb_out.parse(jsonResult); 
                msg = '' + o;
            }
            else{
                msg = 'error';
            }
        }
        catch(Exception e){
             ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, e.getMessage()));
        }
    }
    //----------- search_suggestions_statuses -----------
    public void doTest_search_suggestions_statuses(){
        try{
            WB_OpenApi.WB_search_suggestions_statuses_in wb_in = new WB_OpenApi.WB_search_suggestions_statuses_in(); 
            wb_in.q = '汽车';
            req = wb_in.toRequestUrl();
            string jsonResult = WBUtil.sendRequest(req);
            if(jsonResult.indexOf('error',0) == -1){
                // get response content
                WB_OpenApi.WB_search_suggestions_statuses_out_array wb_out = new WB_OpenApi.WB_search_suggestions_statuses_out_array();
                WB_OpenApi.WB_search_suggestions_statuses_out_array arr = wb_out.parse(jsonResult); 
                msg ='';
                for(WB_OpenApi.WB_search_suggestions_statuses_out o :arr.lst_data){
                    msg += '' + o;
                }
                //msg = '' + outList;
            }
            else{
                msg = 'error';
            }
            json = jsonResult;
        }
        catch(Exception e){
             ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, e.getMessage()));
        }
    }
    
    
    //----------- Show_Comment_List -----------
    public void doTest_Show_Comment_List(){
        
        
        //String id = '3487302598860826';
        //String token = '2.00wd1CkCZqULeE91070bf395rtcnTB';
        //String URL = 'https://api.weibo.com/2/comments/show.json?access_token='+token+'&id='+id ;
        //string jsonResult = WBUtil.sendRequest(url , 'GET');
        
        try{
            WB_OpenApi.WB_Show_Comments_ById_In wb_in = new WB_OpenApi.WB_Show_Comments_ById_In(); 
            wb_in.id = '3487302598860826';
            req = wb_in.toRequestUrl();
            string jsonResult = WBUtil.sendRequest( req , 'GET');
            
            if(jsonResult.indexOf('error',0) == -1){
                // get response content
                WB_OpenApi.WB_Show_Comments_ById_Out_Array wb_out = new WB_OpenApi.WB_Show_Comments_ById_Out_Array();
                WB_OpenApi.WB_Show_Comments_ById_Out_Array arr = wb_out.parse(jsonResult);
                msg = '';
                for(WB_OpenApi.WB_Show_Comments_ById_Out o :arr.comments){
                    msg += ' =============================================================================== ' + o ;
                }
            }
            else{
                msg = 'error';
            }
            json = jsonResult;
        }
        catch(Exception e){
             ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, e.getMessage()));
        }
        
    }
    
     //----------- Reply Comment -----------
    public void doTest_Reply_Comment(){
        
        String token = '2.00wd1CkCZqULeE91070bf395rtcnTB';
        String id = '3487302598860826';
        String cid = '3487361206168524';
        String comment = Math.random()+'';
        
        String URL = 'https://api.weibo.com/2/comments/reply.json';
        String param = 'id='+id+'&cid='+cid+'&comment='+comment+'&access_token='+token;
        string jsonResult = WBUtil.sendRequest( URL , 'POST' , param );
       
        req = url;
        msg = jsonResult;
        json = jsonResult;
    }
    
    
    //----------- Post Comment-----------
    public void doTest_Post_New_Comment(){
        
        String id = '3487302598860826';
        String token = '2.00wd1CkCZqULeE91070bf395rtcnTB';
        String comment = 'TestContent';
        
        String url = 'https://api.weibo.com/2/comments/create.json';
        String param = 'access_token='+token+'&id='+id+'&comment='+comment;
        string jsonResult = WBUtil.sendRequest( url, 'POST', param );
        
        req = url;
        msg = jsonResult;
        json = jsonResult;
    }
    
     //----------- Reply Comment -----------
    public void doTest_QueryMidById(){
        
        String token = '2.00wd1CkCZqULeEc7dcc1a34bmgSZwB';
        String id = '3446486971274760';
        
        String URL = 'https://api.weibo.com/2/statuses/querymid.json?id='+id+'&type=1&access_token='+token;
        
        string jsonResult = WBUtil.sendRequest( URL , 'GET' );
        
		WB_OpenApi.WB_Statuses_QueryMid_ById_Out out = new WB_OpenApi.WB_Statuses_QueryMid_ById_Out();
		out  = out.parse(jsonResult);
		
        req = url;
        msg = out.mid;
        json = jsonResult;
    }
    
}